package cn.tedu.net.thread;
//4个售票窗口,100张票
public class Test4_SaleTickets2 {
    public static void main(String[] args) {
        TicketsThread th = new TicketsThread();
        Thread t1 = new Thread(th, "王大妈");
        Thread t2 = new Thread(th, "李大妈");
        Thread t3 = new Thread(th, "张大妈");
        Thread t4 = new Thread(th, "刘大妈");
        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
class TicketsThread implements Runnable{
    static int ticktes=100;
    @Override
    public void run() {
        while (1==1){
            int a=0;
            int b=0;
            int c=0;
            int d=0;
            if(ticktes>0) {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "=" + ticktes--);
            }
            if(Thread.currentThread().getName().equals("王大妈")){
                a++;
            }else if (Thread.currentThread().getName().toString()=="李大妈"){
                b++;
            }else if (Thread.currentThread().getName().equals("张大妈")){
                c++;
            }else if (Thread.currentThread().getName().equals("刘大妈")){
                d++;
            }
            if(ticktes==0){
                System.out.println("李大妈买了:"+b+"张票");
                System.out.println("王大妈买了:"+a+"张票");
                System.out.println("张大妈买了:"+c+"张票");
                System.out.println("刘大妈买了:"+d+"张票");
                break;
            }
        }
    }
}